/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
 var isUnivalTree = function(root) {
  const traverse = (node, val) => {
      if(node.val !== val) return false;
      if(node.left && !traverse(node.left, val)) return false; 
      if(node.right && !traverse(node.right, val)) return false;
      return true;
  }
  return traverse(root, root.val);
};